package com.topisv.tms.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.Permission;
import com.topisv.tms.entity.Roleperm;

public interface RolepermDao extends PagingAndSortingRepository<Roleperm, Long> {
	
	//List<Roleperm> findByRole_id(int roleid);
	@Modifying
	@Query("delete from Roleperm r where r.role.id = ?1")
	void deleteByRoleId(Long roleId);
	
	@Modifying
	@Query("select rp.permission from Roleperm rp where rp.role.id = ?1")
	List<Permission> findByRoleId(Long roleId);
	
	//APP 权限控制
	@Modifying
	@Query("select rp.permission from Roleperm rp where rp.role.id = ?1 and rp.permission.showname like 'APP%' order by rp.permission.id")
	List<Permission> findAppByRoleId(Long roleId);
}
